package com.ruoyi.web.controller.cinema;

import com.ruoyi.cinema.domain.CarouselFigure;
import com.ruoyi.cinema.service.ICarouselFigureService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图Controller
 *
 * @author HHAOYU
 * @date 2021-01-26
 */
@RestController
@RequestMapping("/cinema/carouselFigure")
public class CarouselFigureController extends BaseController
{
    @Autowired
    private ICarouselFigureService carouselFigureService;

    /**
     * 查询轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:carouselFigure:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarouselFigure carouselFigure)
    {
        startPage();
        List<CarouselFigure> list = carouselFigureService.selectCarouselFigureList(carouselFigure);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:carouselFigure:export')")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CarouselFigure carouselFigure)
    {
        List<CarouselFigure> list = carouselFigureService.selectCarouselFigureList(carouselFigure);
        ExcelUtil<CarouselFigure> util = new ExcelUtil<CarouselFigure>(CarouselFigure.class);
        return util.exportExcel(list, "carouselFigure");
    }

    /**
     * 获取轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:carouselFigure:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(carouselFigureService.selectCarouselFigureById(id));
    }

    /**
     * 新增轮播图
     */
    @PreAuthorize("@ss.hasPermi('cinema:carouselFigure:add')")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarouselFigure carouselFigure)
    {
        return toAjax(carouselFigureService.insertCarouselFigure(carouselFigure));
    }

    /**
     * 修改轮播图
     */
    @PreAuthorize("@ss.hasPermi('cinema:carouselFigure:edit')")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarouselFigure carouselFigure)
    {
        return toAjax(carouselFigureService.updateCarouselFigure(carouselFigure));
    }

    /**
     * 删除轮播图
     */
    @PreAuthorize("@ss.hasPermi('cinema:carouselFigure:remove')")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carouselFigureService.deleteCarouselFigureByIds(ids));
    }
}
